package li.brauch.semesterarbeit.radio;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.RegistryFactory;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

public class RadioPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

	public RadioPreferencePage() {
		super(GRID);
		IPreferenceStore store = RadioPlugin.getDefault().getPreferenceStore();
		setPreferenceStore(store);
		setDescription("General radio settings:\n\nFor radio specific settings look child elements of this preference page.\n\n");
	}

	@Override
	protected void createFieldEditors() {
		
		IExtensionRegistry registry = RegistryFactory.getRegistry();
		IExtensionPoint extensionPoint = registry.getExtensionPoint("li.brauch.semesterarbeit.radio.IRadio");
		
		IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
		
		// Editor for installed radio implementations
		
		String[][] radioImplList = new String[elements.length][2];
		
		int i = 0;
		for (IConfigurationElement element : elements) {
			radioImplList[i][0] = element.getAttribute("name");
			radioImplList[i][1] = element.getAttribute("class");
			i++;
		}
		addField(new RadioGroupFieldEditor("radioImpl", "Choose a radio station", 1, radioImplList, getFieldEditorParent(), true));
		//addField(new ComboFieldEditor("radioImpl", "Choose a radio station", radioImplList, getFieldEditorParent()));
		
		// Editor for online shops
		String[][] onlineShopList = new String[][] {{"exlibris.ch", "http://www.exlibris.ch/search.aspx?clearfilter=1&st=pr&sartikelgruppe_pr=02&Artist=${artist}&AlbumName=${album}"}, {"Amazon.ch", "http://www.amazon.de/s/ref=nb_ss_w?__mk_de_DE=%C5M%C5Z%D5%D1&url=search-alias%3Daps&field-keywords=${artist}%20${album}"}, {"Mininova.com (Torrent)", "http://www.mininova.org/search/?search=${artist}+${album}&cat=0"}};		
		addField(new RadioGroupFieldEditor("shopURL", "Choose a online shop", 1, onlineShopList, getFieldEditorParent(), true));
	}

	public void init(IWorkbench workbench) {
		// tod nothing
		
	}
	
	

}
